package com.wyg.aop;

import com.wyg.entity.User;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
    //value增强的目标对象，defaultImpl引入的增强类
//    @DeclareParents(value = "com.wyg.aop.UserService+",defaultImpl = UserValidateImpl.class)
    public UserValidate userValidate;

    @Pointcut("execution(* com.wyg.aop.UserServiceImpl.printUser(..))")
    public void pointCut(){

    }

    //非环绕通知获取参数的方式
    @Before("pointCut() && args(user)")
    public void before(JoinPoint joinPoint,User user){
        Object[] args = joinPoint.getArgs();
        System.out.println("before ...");
    }

    @After("pointCut()")
    public void after(){
        System.out.println("after ...");
    }

    @AfterReturning("pointCut()")
    public void afterReturning(){
        System.out.println("afterReturning ...");
    }

    @AfterThrowing("pointCut()")
    public void afterThrowing(){
        System.out.println("afterThrowing ...");
    }
    @Around("pointCut()")
    public void around(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("环绕前 ...");
        jp.proceed();
        System.out.println("环绕后 ...");
    }
}
